package com.ruoyi.product.domain;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import org.apache.poi.hpsf.Decimal;

/**
 * 活动对象 product_activity
 * 
 * @author liuhuizhong
 * @date 2025-08-13
 */
public class ProductActivity extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 编号 */
    @Excel(name = "编号")
    private Long activityId;

    /** 活动组id */
    @Excel(name = "活动组id")
    private Long activityGroupId;

    /** 活动组名称 */
    @Excel(name = "活动组名称")
    private String activityGroupName;

    /** 活动名称（如 “2025 春季家具焕新季”） */
    @Excel(name = "活动名称", readConverterExp = "如=,“=2025,春=季家具焕新季”")
    private String activityName;

    /** 活动类型 */
    @Excel(name = "活动类型")
    private Integer activityType;

    /** 活动值 */
    private BigDecimal value;

    /** 活动开始时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "活动开始时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date startTime;

    /** 活动结束时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "活动结束时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date endTime;

    /** 活动详情描述 */
    @Excel(name = "活动详情描述")
    private String activityDesc;

    /** 活动海报图片 */
    @Excel(name = "活动海报图片")
    private String posterUrl;

    /** 活动状态（0：未开始；1：进行中；2：已结束） */
    @Excel(name = "活动状态", readConverterExp = "0=：未开始；1：进行中；2：已结束")
    private Integer status;

    public void setActivityId(Long activityId) 
    {
        this.activityId = activityId;
    }

    public Long getActivityId() 
    {
        return activityId;
    }
    public void setActivityName(String activityName) 
    {
        this.activityName = activityName;
    }

    public String getActivityName() 
    {
        return activityName;
    }
    public void setActivityType(Integer activityType) 
    {
        this.activityType = activityType;
    }

    public Integer getActivityType() 
    {
        return activityType;
    }
    public void setStartTime(Date startTime) 
    {
        this.startTime = startTime;
    }

    public BigDecimal getValue() {
        return value;
    }

    public void setValue(BigDecimal value) {
        this.value = value;
    }

    public Long getActivityGroupId() {
        return activityGroupId;
    }

    public void setActivityGroupId(Long activityGroupId) {
        this.activityGroupId = activityGroupId;
    }

    public String getActivityGroupName() {
        return activityGroupName;
    }

    public void setActivityGroupName(String activityGroupName) {
        this.activityGroupName = activityGroupName;
    }

    public Date getStartTime()
    {
        return startTime;
    }
    public void setEndTime(Date endTime) 
    {
        this.endTime = endTime;
    }

    public Date getEndTime() 
    {
        return endTime;
    }
    public void setActivityDesc(String activityDesc) 
    {
        this.activityDesc = activityDesc;
    }

    public String getActivityDesc() 
    {
        return activityDesc;
    }
    public void setPosterUrl(Object posterUrl)
    {
        if (posterUrl instanceof String) {
            this.posterUrl = (String) posterUrl;
        } else if (posterUrl instanceof String[]) {
            String[] array = (String[]) posterUrl;
            this.posterUrl = array.length > 0 ? array[0] : null;
        } else if (posterUrl instanceof List) {
            List<?> list = (List<?>) posterUrl;
            this.posterUrl = list.isEmpty() ? null : list.get(0).toString();
        } else if (posterUrl != null) {
            this.posterUrl = posterUrl.toString();
        } else {
            this.posterUrl = null;
        }
    }

    public String getPosterUrl() 
    {
        return posterUrl;
    }
    public void setStatus(Integer status) 
    {
        this.status = status;
    }

    public Integer getStatus() 
    {
        return status;
    }

    /**
     * 实时更新活动状态
     * 根据当前时间与活动开始、结束时间的比较，自动更新活动状态
     * @return 更新后的状态值 (0:未开始, 1:进行中, 2:已结束)
     */
    public Integer updateStatus() {
        Date now = new Date();
        if (now.before(this.startTime)) {
            this.status = 0; // 未开始
        } else if (now.after(this.endTime)) {
            this.status = 2; // 已结束
        } else {
            this.status = 1; // 进行中
        }
        return this.status;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("activityId", getActivityId())
            .append("activityName", getActivityName())
            .append("activityType", getActivityType())
            .append("startTime", getStartTime())
            .append("endTime", getEndTime())
            .append("activityDesc", getActivityDesc())
            .append("posterUrl", getPosterUrl())
            .append("status", getStatus())
            .append("createTime", getCreateTime())
            .append("updateTime", getUpdateTime())
            .toString();
    }
}
